package com.firefightingiot.firefightingiot.web.service;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.firefightingiot.firefightingiot.common.base.BaseService;
import com.firefightingiot.firefightingiot.model.DeviceAlarmLog;
import com.firefightingiot.firefightingiot.model.UseDict;
import com.firefightingiot.firefightingiot.model.statistics.*;
import com.firefightingiot.firefightingiot.support.model.RespEntity;
import com.firefightingiot.firefightingiot.support.mybatisplus.QueryWrapper;
import com.firefightingiot.firefightingiot.support.utils.DayUtil;
import com.firefightingiot.firefightingiot.support.utils.requestutil.HttpRequestUtil;
import com.firefightingiot.firefightingiot.web.domain.DeviceAlarmSmallLogDo;
import com.firefightingiot.firefightingiot.web.mapper.DeviceAlarmLogMapper;
import com.firefightingiot.firefightingiot.web.mapper.UseDictMapper;
import com.firefightingiot.firefightingiot.web.mapper.statistics.DeviceAlarmLogAllStatisticsWeekMapper;
import com.firefightingiot.firefightingiot.web.mapper.statistics.DeviceAlarmLogElectricFireStatisticsWeekMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: YangYu
 * @ClassName: HomePageDataService
 * @Date: Created in 15:51 2022/5/30
 * @Description: 首页数据服务
 */
@Service
public class HomePageDataService extends BaseService {
    @Resource
    UseDictMapper useDictMapper;
    @Resource
    private DeviceAlarmLogAllStatisticsWeekMapper deviceAlarmLogAllStatisticsWeekMapper;
    @Resource
    private DeviceAlarmLogMapper deviceAlarmLogMapper;

    public void insertLogStatisticsForToday() throws InterruptedException {
        //insertWeek(jsonObject.getStr("table"), jsonObject.getStr("type"));
        //查询总报警日志统计表
        insertWeek("device_alarm_log_all_today","device_alarm_log_all_statistics_week", null);
        //查询电器火灾日报警日志统计表
        insertWeek("device_alarm_log_electric_fire_today","device_alarm_log_electric_fire_statistics_week", "1");
        //查询建筑消防用水日报警日志统计表
        insertWeek("device_alarm_log_fire_water_today","device_alarm_log_fire_water_statistics_week", "2");
        //查询烟感日报警日志统计表
        insertWeek("device_alarm_log_smoke_today","device_alarm_log_smoke_statistics_week", "3");
        //查询可燃气体日报警日志统计表
        insertWeek("device_alarm_log_gas_today","device_alarm_log_gas_statistics_week", "4");
        //查询自动联网日报警日志统计表
        insertWeek("device_alarm_log_auto_network_today","device_alarm_log_auto_network_statistics_week", "5");
        //查询慧眼识别日报警日志统计表
        insertWeek("device_alarm_log_visualization_today","device_alarm_log_visualization_statistics_week", "6");
        //查询灭火器日报警日志统计表
        insertWeek("device_alarm_log_fire_extinguisher_today","device_alarm_log_fire_extinguisher_statistics_week", "7");
        //查询水泵日报警日志统计表
        insertWeek("device_alarm_log_water_pump_today","device_alarm_log_water_pump_statistics_week", "10");
        //查询加油站日报警日志统计表
        insertWeek("device_alarm_log_visualization_today","device_alarm_log_visualization_statistics_week", "11");
        //查询梯控日报警日志统计表
        insertWeek("device_alarm_log_visualization_today","device_alarm_log_visualization_statistics_week", "12");
        //查询水域日报警日志统计表
        insertWeek("device_alarm_log_visualization_today","device_alarm_log_visualization_statistics_week", "13");
        //查询仓库日报警日志统计表
        insertWeek("device_alarm_log_visualization_today","device_alarm_log_water_immersion_statistics_week", "20");
        //查询充电桩安全日报警日志统计表
        insertWeek("device_alarm_log_charging_station_today","device_alarm_log_charging_station_statistics_week", "22");
    }
    public void insertMonthLogStatisticsForToday() throws InterruptedException {
        //insertWeek(jsonObject.getStr("table"), jsonObject.getStr("type"));
        insertMonth("device_alarm_log_all_today", "device_alarm_log_all_statistics_month", null);
        //查询电器火灾日报警日志统计表
        insertMonth("device_alarm_log_electric_fire_today","device_alarm_log_electric_fire_statistics_month", "1");
        //查询建筑消防用水日报警日志统计表
        insertMonth("device_alarm_log_fire_water_today","device_alarm_log_fire_water_statistics_month", "2");
        //查询烟感日报警日志统计表
        insertMonth("device_alarm_log_smoke_today","device_alarm_log_smoke_statistics_month", "3");
        //查询可燃气体日报警日志统计表
        insertMonth("device_alarm_log_gas_today","device_alarm_log_gas_statistics_month", "4");
        //查询自动联网日报警日志统计表
        insertMonth("device_alarm_log_auto_network_today","device_alarm_log_auto_network_statistics_month", "5");
        //查询慧眼识别日报警日志统计表
        insertMonth("device_alarm_log_visualization_today","device_alarm_log_visualization_statistics_month", "6");
        //查询灭火器日报警日志统计表
        insertMonth("device_alarm_log_fire_extinguisher_today","device_alarm_log_fire_extinguisher_statistics_month", "7");
        //查询水泵日报警日志统计表
        insertMonth("device_alarm_log_water_pump_today","device_alarm_log_water_pump_statistics_month", "10");
        //查询加油站日报警日志统计表
        insertMonth("device_alarm_log_visualization_today","device_alarm_log_visualization_statistics_month", "11");
        //查询梯控日报警日志统计表
        insertMonth("device_alarm_log_visualization_today","device_alarm_log_visualization_statistics_month", "12");
        //查询水域日报警日志统计表
        insertMonth("device_alarm_log_visualization_today","device_alarm_log_visualization_statistics_month", "13");
        //查询仓库日报警日志统计表
        insertMonth("device_alarm_log_water_immersion_today","device_alarm_log_water_immersion_statistics_month", "20");
        //查询充电桩安全日报警日志统计表
        insertMonth("device_alarm_log_charging_station_today","device_alarm_log_charging_station_statistics_month", "22");
    }
    /**
     * @Author YangYu
     * @Description 周数据保存
     * @Date Created in 15:52 2022/5/30
     * @Param [tableOne, tableTwo, deviceClassify]
     */

    public void insertWeek(String table,String tables, String deviceClassify) {
        JSONObject jsonParam = new JSONObject();
        jsonParam.put("table", table);
        jsonParam.put("deviceClassify", deviceClassify);
        jsonParam.put("yesterday", DayUtil.getYestoday());
        List<Map<String, Object>> insertList = getInsertList(jsonParam);
        jsonParam.put("table", tables);
        insertList(insertList, jsonParam);
    }
    /**
     * @Author YangYu
     * @Description 月数据保存
     * @Date Created in 15:52 2022/5/30
     * @Param [tableOne, tableTwo, deviceClassify]
     */

    public void insertMonth(String table,String tables, String deviceClassify) {
        JSONObject jsonParam = new JSONObject();
        jsonParam.put("table", table);
        jsonParam.put("deviceClassify", deviceClassify);
        jsonParam.put("yesterday", DayUtil.getYestoday());
        List<Map<String, Object>> insertList = getInsertList(jsonParam);
        jsonParam.put("table", tables);
        insertList(insertList, jsonParam);
    }
    public void insertList(List<Map<String, Object>> insertList, JSONObject jsonParam) {
        if (!insertList.isEmpty()) {
            //执行批量插入
            jsonParam.put("insertList", insertList);
            if (StrUtil.isBlank(jsonParam.getStr("deviceClassify"))) {
                if (jsonParam.getStr("table").equals("device_alarm_log_all_statistics_month")){
                    deviceAlarmLogAllStatisticsWeekMapper.insertZBM(jsonParam);
                }else {
                    deviceAlarmLogAllStatisticsWeekMapper.insertZB(jsonParam);
                }
            }else if (jsonParam.getStr("deviceClassify").equals("1")) {
                deviceAlarmLogAllStatisticsWeekMapper.insertEleZB(jsonParam);
            }else if (jsonParam.getStr("deviceClassify").equals("2")){
                deviceAlarmLogAllStatisticsWeekMapper.insertWaterZB(jsonParam);
            }else if (jsonParam.getStr("deviceClassify").equals("3")){
                deviceAlarmLogAllStatisticsWeekMapper.insertSmokeZB(jsonParam);
            }else if (jsonParam.getStr("deviceClassify").equals("4")){
                deviceAlarmLogAllStatisticsWeekMapper.insertGasZB(jsonParam);
            }else if (jsonParam.getStr("deviceClassify").equals("5")){
                deviceAlarmLogAllStatisticsWeekMapper.insertAutoNetworkZB(jsonParam);
            }else if (jsonParam.getStr("deviceClassify").equals("6")){
                deviceAlarmLogAllStatisticsWeekMapper.insertVisZB(jsonParam);
            }else if (jsonParam.getStr("deviceClassify").equals("7")){
                deviceAlarmLogAllStatisticsWeekMapper.insertFireExtinguisherZB(jsonParam);
            }else if (jsonParam.getStr("deviceClassify").equals("10")){
                deviceAlarmLogAllStatisticsWeekMapper.insertWaterPumpZB(jsonParam);
            }else if (jsonParam.getStr("deviceClassify").equals("11")){
                deviceAlarmLogAllStatisticsWeekMapper.insertVisZB(jsonParam);
            }else if (jsonParam.getStr("deviceClassify").equals("12")){
                deviceAlarmLogAllStatisticsWeekMapper.insertVisZB(jsonParam);
            }else if (jsonParam.getStr("deviceClassify").equals("13")){
                deviceAlarmLogAllStatisticsWeekMapper.insertVisZB(jsonParam);
            }else if (jsonParam.getStr("deviceClassify").equals("20")) {
                deviceAlarmLogAllStatisticsWeekMapper.insertWaterImmersionZB(jsonParam);
            }else if (jsonParam.getStr("deviceClassify").equals("22")) {
                deviceAlarmLogAllStatisticsWeekMapper.insertChargingStationZB(jsonParam);
            }
        }
    }
    /**
     * @Author YangYu
     * @Description 组装插入周表的数据
     * @Date Created in 15:53 2022/5/30
     * @Param [jsonParam]
     */

    public List<Map<String, Object>> getInsertList(JSONObject jsonParam) {
        List<Map<String, Object>> insertList = new ArrayList<>();

        //系统类型
        String deviceClassify = jsonParam.getStr("deviceClassify");
        //报警单位数据
        List<DeviceAlarmLog> todayAlarmBusinessList = new ArrayList<>();
        //今日报警日志数据
        List<DeviceAlarmLog> todayLogList = new ArrayList<>();
        List<UseDict> useDicts = null;
        if (StrUtil.isBlank(jsonParam.getStr("deviceClassify"))) {
            todayAlarmBusinessList = deviceAlarmLogMapper.getAlarmBusiness(jsonParam);
            todayLogList = deviceAlarmLogMapper.getTodayALarmLogCount(jsonParam);
        }else if (deviceClassify.equals("1") || deviceClassify.equals("22")) {
            todayAlarmBusinessList = deviceAlarmLogMapper.getAlarmBusiness(jsonParam);
            todayLogList = deviceAlarmLogMapper.getTodayALarmLogCount(jsonParam);
            useDicts = useDictMapper.selectList(new QueryWrapper<UseDict>().eq("groupname", "电气火灾监测报警类型"));
        } else if (deviceClassify.equals("2")) {
            todayAlarmBusinessList = deviceAlarmLogMapper.getAlarmBusiness(jsonParam);
            todayLogList = deviceAlarmLogMapper.getTodayALarmLogCount(jsonParam);
            useDicts = useDictMapper.selectList(new QueryWrapper<UseDict>().eq("groupname", "建筑消防用水报警类型"));
        } else if (deviceClassify.equals("3")) {
            todayAlarmBusinessList = deviceAlarmLogMapper.getAlarmBusiness(jsonParam);
            todayLogList = deviceAlarmLogMapper.getTodayALarmLogCount(jsonParam);
            useDicts = useDictMapper.selectList(new QueryWrapper<UseDict>().eq("groupname", "智慧独立烟感报警类型"));
        } else if (deviceClassify.equals("4")) {
            todayAlarmBusinessList = deviceAlarmLogMapper.getAlarmBusiness(jsonParam);
            todayLogList = deviceAlarmLogMapper.getTodayALarmLogCount(jsonParam);
            useDicts = useDictMapper.selectList(new QueryWrapper<UseDict>().eq("groupname", "可燃气体监测报警类型"));
        } else if (deviceClassify.equals("5")) {
            todayAlarmBusinessList = deviceAlarmLogMapper.getAlarmBusiness(jsonParam);
            todayLogList = deviceAlarmLogMapper.getTodayALarmLogCount(jsonParam);
            useDicts = useDictMapper.selectList(new QueryWrapper<UseDict>().eq("groupname", "自动联网报警类型"));
        } else if (deviceClassify.equals("6") || deviceClassify.equals("11") || deviceClassify.equals("12") || deviceClassify.equals("13") || deviceClassify.equals("14") || deviceClassify.equals("15") || deviceClassify.equals("16") || deviceClassify.equals("17")) {
            String groupname = "";
            switch (deviceClassify) {
                case "6":
                    groupname = "慧眼识别报警类型";
                    break;
                case "11":
                    groupname = "加油站报警类型";
                    break;
                case "12":
                    groupname = "智慧梯控报警类型";
                    break;
                case "13":
                    groupname = "智慧水域报警类型";
                    break;
//                case "14":
//                    groupname = "慧眼识别报警类型";
//                    break;
//                case "15":
//                    groupname = "慧眼识别报警类型";
//                    break;
                case "16":
                    groupname = "明厨亮灶报警类型";
                    break;
//                case "17":
//                    groupname = "慧眼识别报警类型";
//                    break;
            }
            todayAlarmBusinessList = deviceAlarmLogMapper.getAlarmBusiness(jsonParam);
            todayLogList = deviceAlarmLogMapper.getTodayALarmLogCount(jsonParam);
            useDicts = useDictMapper.selectList(new QueryWrapper<UseDict>().eq("groupname", groupname));
        } else if (deviceClassify.equals("7")) {
            todayAlarmBusinessList = deviceAlarmLogMapper.getAlarmBusiness(jsonParam);
            todayLogList = deviceAlarmLogMapper.getTodayALarmLogCount(jsonParam);
            useDicts = useDictMapper.selectList(new QueryWrapper<UseDict>().eq("groupname", "智能灭火器报警类型"));
        }
        Map<String, String> keyMap = new HashMap<>();
        if (useDicts != null) {
            for (UseDict use : useDicts) {
                keyMap.put(use.getName(), use.getId());
            }
        }
        for (DeviceAlarmLog deviceAlarmLog : todayAlarmBusinessList){
            Map<String, Object> map = new HashMap<>();
            map = getMapByList(todayLogList,map,deviceAlarmLog.getBusinessId(),deviceClassify,keyMap);
            String todayTime = DayUtil.getYestoday();
            map.put("alldate",todayTime);
            map.put("date",todayTime.substring(5));
            map.put("businessId", deviceAlarmLog.getBusinessId());
            map.put("orgId", deviceAlarmLog.getOrgId());
            map.put("allId", deviceAlarmLog.getAllId());
            insertList.add(map);
        }
        return insertList;
    }

    public static void main(String[] args) {
        System.out.println(DateUtil.today());
    }
    public Map<String, Object> getMapByList(List<DeviceAlarmLog> todayLogList,Map<String, Object> map,String businessId ,String deviceClassify,Map<String, String> keyMap) {
        if (StrUtil.isBlank(deviceClassify)) {
            Integer allCount = 0;//总数目
            Integer todayOtherCount = 0;//其他数目
            Integer todayFireCount = 0;//电气火灾报警数目
            Integer todayWaterCount = 0;//消防用水报警数目
            Integer todaySmokeCount = 0;//烟感报警数目
            Integer todayGasCount = 0;//气体报警数目
            Integer todaySmartEyeCount = 0;//慧眼识别报警数目
            Integer todayFireExtinguisherCount = 0;//灭火器报警数目
            Integer todayWaterImmersionCount = 0;//水浸报警数目
            for (DeviceAlarmLog deviceAlarmLog : todayLogList) {
                if (deviceAlarmLog.getBusinessId().equals(businessId)) {
                    if (deviceAlarmLog.getDeviceClassify() == null) {
                        continue;
                    } else if (deviceAlarmLog.getDeviceClassify().equals("1")) {
                        todayFireCount = todayFireCount + 1;
                    } else if (deviceAlarmLog.getDeviceClassify().equals("2")) {
                        todayWaterCount = todayWaterCount + 1;
                    } else if (deviceAlarmLog.getDeviceClassify().equals("3")) {
                        todaySmokeCount = todaySmokeCount + 1;
                    }else if (deviceAlarmLog.getDeviceClassify().equals("4")) {
                        todayGasCount = todayGasCount + 1;
                    }else if (deviceAlarmLog.getDeviceClassify().equals("6")) {
                        todaySmartEyeCount = todaySmartEyeCount + 1;
                    }else if (deviceAlarmLog.getDeviceClassify().equals("7")) {
                        todayFireExtinguisherCount = todayFireExtinguisherCount + 1;
                    }else if (deviceAlarmLog.getDeviceClassify().equals("20")) {
                        todayWaterImmersionCount = todayWaterImmersionCount + 1;
                    } else {
                        todayOtherCount = todayOtherCount + 1;
                    }
                }
            }
            allCount = todayOtherCount + todayFireCount + todayWaterCount + todaySmokeCount + todayGasCount + todaySmartEyeCount + todayFireExtinguisherCount + todayWaterImmersionCount;
            map.put("todayFireCount", todayFireCount);
            map.put("todayWaterCount", todayWaterCount);
            map.put("todaySmokeCount", todaySmokeCount);
            map.put("todayOtherCount", todayOtherCount + todayGasCount + todaySmartEyeCount + todayFireExtinguisherCount + todayWaterImmersionCount);
            map.put("todayGasCount", todayGasCount);
            map.put("todaySmartEyeCount", todaySmartEyeCount);
            map.put("todayFireExtinguisherEyeCount", todayFireExtinguisherCount);
            map.put("todayWaterImmersionCount", todayWaterImmersionCount);
            map.put("allCount", allCount);
        }else if (deviceClassify.equals("1") || deviceClassify.equals("22")) {
            Integer allCount = 0;//总数目
            Integer todayVoltageCount = 0;//电压报警数目
            Integer todayCurrentCount = 0;//电流报警数目
            Integer todayTemperatureCount = 0;//温度报警数目
            Integer todayLeakageCurrentCount = 0;//漏电流报警数目

            for (DeviceAlarmLog deviceAlarmLog : todayLogList) {
                if (deviceAlarmLog.getBusinessId().equals(businessId)) {
                    if (deviceAlarmLog.getAlarmType() == null) {
                        continue;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("电压报警"))) {
                        todayVoltageCount = todayVoltageCount + 1;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("电流报警"))) {
                        todayCurrentCount = todayCurrentCount + 1;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("温度报警"))) {
                        todayTemperatureCount = todayTemperatureCount + 1;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("漏电流报警"))) {
                        todayLeakageCurrentCount = todayLeakageCurrentCount + 1;
                    }
                }
            }
            allCount = todayVoltageCount + todayCurrentCount + todayTemperatureCount + todayLeakageCurrentCount;
            map.put("todayVoltageCount", todayVoltageCount);
            map.put("todayCurrentCount", todayCurrentCount);
            map.put("todayTemperatureCount", todayTemperatureCount);
            map.put("todayLeakageCurrentCount", todayLeakageCurrentCount);
            map.put("allCount", allCount);
        } else if (deviceClassify.equals("2")) {
            Integer allCount = 0;//总数目
            Integer todayHydraulicPressureCount = 0;//液压报警数目
            Integer todayLevelCount = 0;//液位报警数目
            for (DeviceAlarmLog deviceAlarmLog : todayLogList) {
                if (deviceAlarmLog.getBusinessId().equals(businessId)) {
                    if (deviceAlarmLog.getAlarmType() == null) {
                        continue;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("液压报警"))) {
                        todayHydraulicPressureCount = todayHydraulicPressureCount+1;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("液位报警"))) {
                        todayLevelCount = todayLevelCount+1;
                    }
                }
            }
            allCount = todayHydraulicPressureCount + todayLevelCount;
            map.put("todayHydraulicPressureCount", todayHydraulicPressureCount);
            map.put("todayLevelCount", todayLevelCount);
            map.put("allCount", allCount);
        } else if (deviceClassify.equals("3")) {
            Integer allCount = 0;//总数目
            Integer todaySmokeCount = 0;//独立烟感报警
            Integer todaySignalCount = 0;//信号异常报警
            for (DeviceAlarmLog deviceAlarmLog : todayLogList) {
                if (deviceAlarmLog.getBusinessId().equals(businessId)) {
                    if (deviceAlarmLog.getAlarmType() == null) {
                        continue;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("独立烟感报警"))) {
                        todaySmokeCount = todaySmokeCount+1;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("信号异常报警"))) {
                        todaySignalCount = todaySignalCount+1;
                    }
                }
            }
            allCount = todaySmokeCount + todaySignalCount;
            map.put("todaySmokeCount", todaySmokeCount);
            map.put("todaySignalCount", todaySignalCount);
            map.put("allCount", allCount);
        } else if (deviceClassify.equals("4")) {
            Integer allCount = 0;//总数目
            Integer todayGasCount = 0;//可燃气报警
            for (DeviceAlarmLog deviceAlarmLog : todayLogList) {
                if (deviceAlarmLog.getBusinessId().equals(businessId)) {
                    if (deviceAlarmLog.getAlarmType() == null) {
                        continue;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("可燃气报警"))) {
                        todayGasCount = todayGasCount+1;
                    }
                }
            }
            allCount = todayGasCount;
            map.put("todayGasCount", todayGasCount);
            map.put("allCount", allCount);
        } else if (deviceClassify.equals("5")) {
            Integer allCount = 0;//总数目
            Integer todaySystemEventCount = 0;//系统事件
            Integer todayFaultCount = 0;//故障
            Integer todayFireAlarmCount = 0;//火警
            for (DeviceAlarmLog deviceAlarmLog : todayLogList) {
                if (deviceAlarmLog.getBusinessId().equals(businessId)) {
                    if (deviceAlarmLog.getAlarmType() == null) {
                        continue;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("火警"))) {
                        todayFireAlarmCount = todayFireAlarmCount+1;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("故障"))) {
                        todayFaultCount = todayFaultCount+1;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("系统事件"))) {
                        todaySystemEventCount = todaySystemEventCount+1;
                    }
                }
            }
            allCount = todaySystemEventCount + todayFaultCount + todayFireAlarmCount;
            map.put("todaySystemEventCount", todaySystemEventCount);
            map.put("todayFaultCount", todayFaultCount);
            map.put("todayFireAlarmCount", todayFireAlarmCount);
            map.put("allCount", allCount);
        } else if (deviceClassify.equals("6")) {
            Integer allCount = 0;//总数目
            Integer todayFireCount = 0;//火焰报警
            Integer todayLeaveCount = 0;//脱岗离岗报警
            Integer todayPassWayCount = 0;//消防通道报警

            for (DeviceAlarmLog deviceAlarmLog : todayLogList) {
                if (deviceAlarmLog.getBusinessId().equals(businessId)) {
                    if (deviceAlarmLog.getAlarmType() == null) {
                        continue;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("火焰报警"))) {
                        todayFireCount = todayFireCount+1;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("脱岗离岗报警"))) {
                        todayLeaveCount = todayLeaveCount+1;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("消防通道报警"))) {
                        todayPassWayCount = todayPassWayCount+1;
                    }
                }
            }
            allCount = todayFireCount + todayLeaveCount + todayPassWayCount;
            map.put("todayFireCount", todayFireCount);
            map.put("todayLeaveCount", todayLeaveCount);
            map.put("todayPassWayCount", todayPassWayCount);
            map.put("allCount", allCount);
        } else if (deviceClassify.equals("7")) {
            Integer allCount = 0;//总数目
            Integer todayPressureCount = 0;//压力报警数目
            Integer todayEmbezzlementCount = 0;//挪用报警数目
            for (DeviceAlarmLog deviceAlarmLog : todayLogList) {
                if (deviceAlarmLog.getBusinessId().equals(businessId)) {
                    if (deviceAlarmLog.getAlarmType() == null) {
                        continue;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("手提灭火器"))) {
                        todayPressureCount = todayPressureCount+1;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("悬挂式灭火器"))) {
                        todayEmbezzlementCount = todayEmbezzlementCount+1;
                    }
                }
            }
            allCount = todayPressureCount + todayEmbezzlementCount;
            map.put("todayPressureCount", todayPressureCount);
            map.put("todayEmbezzlementCount", todayEmbezzlementCount);
            map.put("allCount", allCount);
        } else if (deviceClassify.equals("10")) {
            Integer allCount = 0;//总数目
            Integer todayVoltageCount = 0;//电压故障报警数目
            for (DeviceAlarmLog deviceAlarmLog : todayLogList) {
                if (deviceAlarmLog.getBusinessId().equals(businessId)) {
                    if (deviceAlarmLog.getAlarmType() == null) {
                        continue;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("电压故障报警"))) {
                        todayVoltageCount = todayVoltageCount+1;
                    }
                }
            }
            allCount = todayVoltageCount;
            map.put("todayVoltageCount", todayVoltageCount);
            map.put("allCount", allCount);
        } else if (deviceClassify.equals("11")) {
            Integer allCount = 0;//总数目
            Integer todayPersonnelDetectionCount = 0;//人员检测
            Integer todayUnloadingAnalysisCount = 0;//卸油分析
            for (DeviceAlarmLog deviceAlarmLog : todayLogList) {
                if (deviceAlarmLog.getBusinessId().equals(businessId)) {
                    if (deviceAlarmLog.getAlarmType() == null) {
                        continue;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("人员检测"))) {
                        todayPersonnelDetectionCount = todayPersonnelDetectionCount+1;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("卸油分析"))) {
                        todayUnloadingAnalysisCount = todayUnloadingAnalysisCount+1;
                    }
                }
            }
            allCount = todayPersonnelDetectionCount + todayUnloadingAnalysisCount;
            map.put("todayPersonnelDetectionCount", todayPersonnelDetectionCount);
            map.put("todayUnloadingAnalysisCount", todayUnloadingAnalysisCount);
            map.put("allCount", allCount);
        } else if (deviceClassify.equals("12")) {
            Integer allCount = 0;//总数目
            Integer todayElectricVehicleCount = 0;//电动车识别报警
            for (DeviceAlarmLog deviceAlarmLog : todayLogList) {
                if (deviceAlarmLog.getBusinessId().equals(businessId)) {
                    if (deviceAlarmLog.getAlarmType() == null) {
                        continue;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("电动车识别报警"))) {
                        todayElectricVehicleCount = todayElectricVehicleCount+1;
                    }
                }
            }
            allCount = todayElectricVehicleCount;
            map.put("todayElectricVehicleCount", todayElectricVehicleCount);
            map.put("allCount", allCount);
        } else if (deviceClassify.equals("13")) {
            Integer allCount = 0;//总数目
            Integer todayAlertIdentificationCount = 0;//警戒识别
            for (DeviceAlarmLog deviceAlarmLog : todayLogList) {
                if (deviceAlarmLog.getBusinessId().equals(businessId)) {
                    if (deviceAlarmLog.getAlarmType() == null) {
                        continue;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("警戒识别"))) {
                        todayAlertIdentificationCount = todayAlertIdentificationCount+1;
                    }
                }
            }
            allCount = todayAlertIdentificationCount;
            map.put("todayAlertIdentificationCount", todayAlertIdentificationCount);
            map.put("allCount", allCount);
        }else if (deviceClassify.equals("20")) {
            Integer allCount = 0;//总数目
            Integer todayWaterImmersionCount = 0;//水浸
            for (DeviceAlarmLog deviceAlarmLog : todayLogList) {
                if (deviceAlarmLog.getBusinessId().equals(businessId)) {
                    if (deviceAlarmLog.getAlarmType() == null) {
                        continue;
                    } else if (deviceAlarmLog.getAlarmType().equals(keyMap.get("水浸告警"))) {
                        todayWaterImmersionCount = todayWaterImmersionCount+1;
                    }
                }
            }
            allCount = todayWaterImmersionCount;
            map.put("todayWaterImmersionCount", todayWaterImmersionCount);
            map.put("allCount", allCount);
        }
        return map;
    }
    @Resource
    private DeviceAlarmLogElectricFireStatisticsWeekMapper deviceAlarmLogElectricFireStatisticsWeekMapper;
    /**
     * @Author YangYu
     * @Description 今天之前一周报警数据
     * @Date Created in 14:59 2022/6/2
     * @Param [jsonParam]
     */

    public RespEntity weekAlarmLog(JSONObject jsonParam) {
        //处理支持form-data和json两种方式
        jsonParam = HttpRequestUtil.commonHttpRequestParamConvert(getRequest());
        //调用token验证接口
        com.alibaba.fastjson.JSONObject token = makeDataForToken(jsonParam,"systemsetup","config","getDecodeToken","systemsetup");
        if(StrUtil.isNotBlank(token.getString("methodCodeFlag"))) return RespEntity.expire();
        if(StrUtil.isNotBlank(token.getString("methodErrorFlag"))) return RespEntity.fail(token.getString("msg"));
        String homeId = token.getString("home_id");
        String userType = token.getString("user_type");
        if(userType.equals("1")){//为机构用户
            //rest请求系统设置模块的机构和子机构列表接口
            if(StrUtil.isNotBlank(jsonParam.getStr("businessId"))){//机构用户访问单位用户的数据
                jsonParam.put("businessId",jsonParam.getStr("businessId"));
            }else{
                jsonParam.put("orgId",homeId);
            }
        }else if(userType.equals("2")){//为单位用户
            jsonParam.put("businessId",homeId);
        }
        //系统类型
        String deviceClassify = jsonParam.getStr("deviceClassify");
        List<Map<String, Object>> insertList = new ArrayList<>();
        if (userType.equals("1")){
            if (StrUtil.isBlank(deviceClassify)){
                List<DeviceAlarmLogAllStatisticsWeek> deviceAlarmLogAllStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogAllStatisticsDateWeekList();
                for (DeviceAlarmLogAllStatisticsWeek dl : deviceAlarmLogAllStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapWeekList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("1")){
                List<DeviceAlarmLogElectricFireStatisticsWeek> deviceAlarmLogElectricFireStatisticsWeekDateList = deviceAlarmLogElectricFireStatisticsWeekMapper.deviceAlarmLogElectricFireStatisticsWeekDateList();
                for (DeviceAlarmLogElectricFireStatisticsWeek dl : deviceAlarmLogElectricFireStatisticsWeekDateList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapWeekList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("2")){
                List<DeviceAlarmLogFireWaterStatisticsWeek> deviceAlarmLogWaterStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogWaterStatisticsDateWeekList();
                for (DeviceAlarmLogFireWaterStatisticsWeek dl : deviceAlarmLogWaterStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapWeekList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("3")){
                List<DeviceAlarmLogSmokeStatisticsWeek> deviceAlarmLogSmokeStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogSmokeStatisticsDateWeekList();
                for (DeviceAlarmLogSmokeStatisticsWeek dl : deviceAlarmLogSmokeStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapWeekList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("4")){
                List<DeviceAlarmLogGasStatisticsWeek> deviceAlarmLogGasStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogGasStatisticsDateWeekList();
                for (DeviceAlarmLogGasStatisticsWeek dl : deviceAlarmLogGasStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapWeekList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("5")){
                List<DeviceAlarmLogAutoNetworkStatisticsWeek> deviceAlarmLogAutoNetStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogAutoNetStatisticsDateWeekList();
                for (DeviceAlarmLogAutoNetworkStatisticsWeek dl : deviceAlarmLogAutoNetStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapWeekList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("6") || deviceClassify.equals("11") || deviceClassify.equals("12") || deviceClassify.equals("13")){
                List<DeviceAlarmLogVisualizationStatisticsWeek> deviceAlarmLogVisualizationStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogVisualizationStatisticsDateWeekList();
                for (DeviceAlarmLogVisualizationStatisticsWeek dl : deviceAlarmLogVisualizationStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapWeekList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("7")){
                List<DeviceAlarmLogFireExtinguisherStatisticsWeek> deviceAlarmLogFireExtinguisherStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogFireExtinguisherStatisticsDateWeekList();
                for (DeviceAlarmLogFireExtinguisherStatisticsWeek dl : deviceAlarmLogFireExtinguisherStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapWeekList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("10")){
                List<DeviceAlarmLogWaterPumpStatisticsWeek> deviceAlarmLogWaterPumpStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogWaterPumpStatisticsDateWeekList();
                for (DeviceAlarmLogWaterPumpStatisticsWeek dl : deviceAlarmLogWaterPumpStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapWeekList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("22")){
                List<DeviceAlarmLogChargingStationStatisticsWeek> deviceAlarmLogWaterPumpStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogChargingStationStatisticsDateWeekList();
                for (DeviceAlarmLogChargingStationStatisticsWeek dl : deviceAlarmLogWaterPumpStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapWeekList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }

        }else if (userType.equals("2")){
            if (StrUtil.isBlank(deviceClassify)){
                List<DeviceAlarmLogAllStatisticsWeek> deviceAlarmLogAllStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogAllStatisticsBusinessWeekList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogAllStatisticsDateWeekList);
            }else if (deviceClassify.equals("1")){
                List<DeviceAlarmLogElectricFireStatisticsWeek> deviceAlarmLogElectricFireStatisticsWeekDateList = deviceAlarmLogElectricFireStatisticsWeekMapper.deviceAlarmLogElectricFireStatisticsBusinessWeekList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogElectricFireStatisticsWeekDateList);
            }else if (deviceClassify.equals("2")){
                List<DeviceAlarmLogFireWaterStatisticsWeek> deviceAlarmLogWaterStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogWaterStatisticsBusinessWeekList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogWaterStatisticsDateWeekList);
            }else if (deviceClassify.equals("3")){
                List<DeviceAlarmLogSmokeStatisticsWeek> deviceAlarmLogSmokeStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogSmokeStatisticsBusinessWeekList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogSmokeStatisticsDateWeekList);
            }else if (deviceClassify.equals("4")){
                List<DeviceAlarmLogGasStatisticsWeek> deviceAlarmLogGasStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogGasStatisticsBusinessWeekList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogGasStatisticsDateWeekList);
            }else if (deviceClassify.equals("5")){
                List<DeviceAlarmLogAutoNetworkStatisticsWeek> deviceAlarmLogAutoNetStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogAutoNetStatisticsBusinessWeekList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogAutoNetStatisticsDateWeekList);
            }else if (deviceClassify.equals("6") || deviceClassify.equals("11") || deviceClassify.equals("12") || deviceClassify.equals("13")){
                List<DeviceAlarmLogVisualizationStatisticsWeek> deviceAlarmLogVisualizationStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogVisualizationStatisticsBusinessWeekList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogVisualizationStatisticsDateWeekList);
            }else if (deviceClassify.equals("7")){
                List<DeviceAlarmLogFireExtinguisherStatisticsWeek> deviceAlarmLogFireExtinguisherStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogFireExtinguisherStatisticsBusinessWeekList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogFireExtinguisherStatisticsDateWeekList);
            }else if (deviceClassify.equals("10")){
                List<DeviceAlarmLogWaterPumpStatisticsWeek> deviceAlarmLogWaterPumpStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogWaterPumpStatisticsBusinessWeekList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogWaterPumpStatisticsDateWeekList);
            }else if (deviceClassify.equals("22")){
                List<DeviceAlarmLogChargingStationStatisticsWeek> deviceAlarmLogChargingStationStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogChargingStationStatisticsBusinessWeekList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogChargingStationStatisticsWeekList);
            }
        }
        return RespEntity.success(insertList);
    }
    public Map<String, Object> getMapWeekList(Map<String, Object> map,String date,String deviceClassify,JSONObject jsonParam) {
        if (StrUtil.isBlank(deviceClassify)){
            List<DeviceAlarmLogAllStatisticsWeek> deviceAlarmLogAllStatisticsWeeks = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogAllStatisticsWeekList(jsonParam.getStr("orgId"));
            Integer allCount = 0;//总数目
            Integer weeOtherCount = 0;//其他数目
            Integer weeFileCount = 0;//电气火灾报警数目
            Integer weeWaterCount = 0;//消防用水报警数目
            Integer weeSmokeCount = 0;//烟感报警数目
            Integer weeGasCount = 0;//气体报警数目
            Integer weeSmartEyeCount = 0;//慧眼识别报警数目
            Integer weeFireExtinguisherCount = 0;//灭火器报警数目
            Integer weeWaterImmersionCount = 0;//水浸报警数目
            for (DeviceAlarmLogAllStatisticsWeek dw : deviceAlarmLogAllStatisticsWeeks){
                if (dw.getDate().equals(date)){
                    weeOtherCount = weeOtherCount + Integer.parseInt(dw.getWeeOtherCount());
                    weeFileCount = weeFileCount + Integer.parseInt(dw.getWeeFileCount());
                    weeWaterCount = weeWaterCount + Integer.parseInt(dw.getWeeWaterCount());
                    weeSmokeCount = weeSmokeCount + Integer.parseInt(dw.getWeeSmokeCount());
                    weeGasCount = weeGasCount + Integer.parseInt(dw.getWeeGasCount());
                    weeSmartEyeCount = weeSmartEyeCount + Integer.parseInt(dw.getWeeSmartEyeCount());
                    weeFireExtinguisherCount = weeFireExtinguisherCount + Integer.parseInt(dw.getWeeFireExtinguisherCount());
                    weeWaterImmersionCount = weeWaterImmersionCount + Integer.parseInt(dw.getWeeWaterImmersionCount());
                }
            }
            allCount = weeOtherCount + weeFileCount + weeWaterCount + weeSmokeCount;
            map.put("weeFileCount", weeFileCount);
            map.put("weeWaterCount", weeWaterCount);
            map.put("weeSmokeCount", weeSmokeCount);
            map.put("weeOtherCount", weeOtherCount+weeGasCount+weeSmartEyeCount+weeFireExtinguisherCount+weeWaterImmersionCount);
            map.put("weeGasCount", weeGasCount);
            map.put("weeSmartEyeCount", weeSmartEyeCount);
            map.put("weeFireExtinguisherCount", weeFireExtinguisherCount);
            map.put("weeWaterImmersionCount", weeWaterImmersionCount);
            map.put("weeWareHouseOtherCount", weeOtherCount);//仓库安全用
            map.put("allCount", allCount);
        }else if (deviceClassify.equals("1")){
            List<DeviceAlarmLogElectricFireStatisticsWeek> deviceAlarmLogElectricFireStatisticsWeekList = deviceAlarmLogElectricFireStatisticsWeekMapper.deviceAlarmLogElectricFireStatisticsWeekList(jsonParam.getStr("orgId"));
            Integer allCount = 0;//总数目
            Integer weekVoltageCount = 0;//电压报警数目
            Integer weekCurrentCount = 0;//电流报警数目
            Integer weekTemperatureCount = 0;//温度报警数目
            Integer weekLeakageCurrentCount = 0;//漏电流报警数目
            for (DeviceAlarmLogElectricFireStatisticsWeek dw : deviceAlarmLogElectricFireStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekVoltageCount = weekVoltageCount + Integer.parseInt(dw.getWeekVoltageCount());
                    weekCurrentCount = weekCurrentCount + Integer.parseInt(dw.getWeekCurrentCount());
                    weekTemperatureCount = weekTemperatureCount + Integer.parseInt(dw.getWeekTemperatureCount());
                    weekLeakageCurrentCount = weekLeakageCurrentCount + Integer.parseInt(dw.getWeekLeakageCurrentCount());
                }
            }
            allCount = weekVoltageCount + weekCurrentCount + weekTemperatureCount + weekLeakageCurrentCount;
            map.put("weekVoltageCount",weekVoltageCount);
            map.put("weekCurrentCount",weekCurrentCount);
            map.put("weekTemperatureCount",weekTemperatureCount);
            map.put("weekLeakageCurrentCount",weekLeakageCurrentCount);
            map.put("allCount",allCount);
        }else if (deviceClassify.equals("2")){
            Integer allCount = 0;//总数目
            Integer weekHydraulicPressureCount = 0;//液压报警数目
            Integer weekLevelCount = 0;//液位报警数目
            List<DeviceAlarmLogFireWaterStatisticsWeek> deviceAlarmLogWaterStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogWaterStatisticsWeekList(jsonParam.getStr("orgId"));
            for (DeviceAlarmLogFireWaterStatisticsWeek dw : deviceAlarmLogWaterStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekHydraulicPressureCount = weekHydraulicPressureCount + Integer.parseInt(dw.getWeekHydraulicPressureCount());
                    weekLevelCount = weekLevelCount + Integer.parseInt(dw.getWeekLevelCount());
                }
            }
            allCount = weekHydraulicPressureCount + weekLevelCount;
            map.put("weekHydraulicPressureCount", weekHydraulicPressureCount);
            map.put("weekLevelCount", weekLevelCount);
            map.put("allCount", allCount);
        }else if (deviceClassify.equals("3")){
            Integer allCount = 0;//总数目
            Integer weekSmokeCount = 0;//独立烟感报警
            Integer weekSignalCount = 0;//信号异常报警
            List<DeviceAlarmLogSmokeStatisticsWeek> deviceAlarmLogSmokeStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogSmokeStatisticsWeekList(jsonParam.getStr("orgId"));
            for (DeviceAlarmLogSmokeStatisticsWeek dw : deviceAlarmLogSmokeStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekSmokeCount = weekSmokeCount + Integer.parseInt(dw.getWeekSmokeCount());
                    weekSignalCount = weekSignalCount + Integer.parseInt(dw.getWeekSignalCount());
                }
            }
            allCount = weekSmokeCount + weekSignalCount;
            map.put("weekSmokeCount", weekSmokeCount);
            map.put("weekSignalCount", weekSignalCount);
            map.put("allCount", allCount);
        }else if (deviceClassify.equals("4")){
            Integer allCount = 0;//总数目
            Integer weekGasCount = 0;//可燃气报警
            List<DeviceAlarmLogGasStatisticsWeek> deviceAlarmLogGasStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogGasStatisticsWeekList(jsonParam.getStr("orgId"));
            for (DeviceAlarmLogGasStatisticsWeek dw : deviceAlarmLogGasStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekGasCount = weekGasCount + Integer.parseInt(dw.getWeekGasCount());
                }
            }
            map.put("weekGasCount", weekGasCount);
            map.put("allCount", weekGasCount);
        }else if (deviceClassify.equals("5")){
            Integer allCount = 0;//总数目
            Integer weekSystemEventCount = 0;//系统事件
            Integer weekFaultCount = 0;//故障
            Integer weekFireAlarmCount = 0;//火警
            List<DeviceAlarmLogAutoNetworkStatisticsWeek> deviceAlarmLogAutoNetStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogAutoNetStatisticsWeekList(jsonParam.getStr("orgId"));
            for (DeviceAlarmLogAutoNetworkStatisticsWeek dw : deviceAlarmLogAutoNetStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekSystemEventCount = weekSystemEventCount + Integer.parseInt(dw.getWeekSystemEventCount());
                    weekFaultCount = weekFaultCount + Integer.parseInt(dw.getWeekFaultCount());
                    weekFireAlarmCount = weekSystemEventCount + Integer.parseInt(dw.getWeekFireAlarmCount());
                }
            }
            allCount = weekSystemEventCount + weekFaultCount + weekFireAlarmCount;
            map.put("weekSystemEventCount", weekSystemEventCount);
            map.put("weekFaultCount", weekFaultCount);
            map.put("weekFireAlarmCount", weekFireAlarmCount);
            map.put("allCount", allCount);
        }else if (deviceClassify.equals("6") || deviceClassify.equals("11") || deviceClassify.equals("12") || deviceClassify.equals("13")){
            Integer allCount = 0;//总数目
            Integer weekFireCount = 0;//火焰报警
            Integer weekLeaveCount = 0;//脱岗离岗报警
            Integer weekPassWayCount = 0;//消防通道报警
            Integer weekElectricVehicleCount = 0;//电动车报警
            Integer weekPersonnelDetectionCount = 0;//人员检测
            Integer weekUnloadingAnalysisCount = 0;//卸油分析
            Integer weekAlertIdentificationCount = 0;//警戒识别
            Integer weekVideoOcclusionCount = 0;//视频遮挡
            List<DeviceAlarmLogVisualizationStatisticsWeek> deviceAlarmLogVisualizationStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogVisualizationStatisticsWeekList(jsonParam.getStr("orgId"));
            for (DeviceAlarmLogVisualizationStatisticsWeek dw : deviceAlarmLogVisualizationStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekFireCount = weekFireCount + Integer.parseInt(dw.getWeekFireCount());
                    weekLeaveCount = weekLeaveCount + Integer.parseInt(dw.getWeekLeaveCount());
                    weekPassWayCount = weekPassWayCount + Integer.parseInt(dw.getWeekPassWayCount());
                    weekElectricVehicleCount = weekElectricVehicleCount + Integer.parseInt(dw.getWeekElectricVehicleCount());
                    weekPersonnelDetectionCount = weekPersonnelDetectionCount + Integer.parseInt(dw.getWeekPersonnelDetectionCount());
                    weekUnloadingAnalysisCount = weekUnloadingAnalysisCount + Integer.parseInt(dw.getWeekUnloadingAnalysisCount());
                    weekAlertIdentificationCount = weekAlertIdentificationCount + Integer.parseInt(dw.getWeekAlertIdentificationCount());
                    weekVideoOcclusionCount = weekVideoOcclusionCount + Integer.parseInt(dw.getWeekVideoOcclusionCount());
                }
            }
            map.put("weekFireCount", weekFireCount);
            map.put("weekLeaveCount", weekLeaveCount);
            map.put("weekPassWayCount", weekPassWayCount);
            map.put("weekElectricVehicleCount", weekElectricVehicleCount);
            map.put("weekPersonnelDetectionCount", weekPersonnelDetectionCount);
            map.put("weekUnloadingAnalysisCount", weekUnloadingAnalysisCount);
            map.put("weekAlertIdentificationCount", weekAlertIdentificationCount);
            map.put("weekVideoOcclusionCount", weekVideoOcclusionCount);
            map.put("allCount", allCount);
        }else if (deviceClassify.equals("7")){
            Integer allCount = 0;//总数目
            Integer weekPressureCount = 0;//压力报警
            Integer weekEmbezzlementCount = 0;//挪用报警
            List<DeviceAlarmLogFireExtinguisherStatisticsWeek> deviceAlarmLogFireExtinguisherStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogFireExtinguisherStatisticsWeekList(jsonParam.getStr("orgId"));
            for (DeviceAlarmLogFireExtinguisherStatisticsWeek dw : deviceAlarmLogFireExtinguisherStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekPressureCount = weekPressureCount + Integer.parseInt(dw.getWeekPressureCount());
                    weekEmbezzlementCount = weekEmbezzlementCount + Integer.parseInt(dw.getWeekEmbezzlementCount());
                }
            }
            allCount = weekPressureCount + weekEmbezzlementCount;
            map.put("weekPressureCount", weekPressureCount);
            map.put("weekEmbezzlementCount", weekEmbezzlementCount);
            map.put("allCount", allCount);
        }else if (deviceClassify.equals("10")){
            Integer allCount = 0;//总数目
            Integer weekVoltageCount = 0;//电压故障报警数目
            List<DeviceAlarmLogWaterPumpStatisticsWeek> deviceAlarmLogWaterPumpStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogWaterPumpStatisticsWeekList(jsonParam.getStr("orgId"));
            for (DeviceAlarmLogWaterPumpStatisticsWeek dw : deviceAlarmLogWaterPumpStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekVoltageCount = weekVoltageCount + Integer.parseInt(dw.getWeekVoltageCount());
                }
            }
            map.put("weekVoltageCount", weekVoltageCount);
            map.put("allCount", weekVoltageCount);
        }else if (deviceClassify.equals("22")){
            List<DeviceAlarmLogChargingStationStatisticsWeek> deviceAlarmLogElectricFireStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogChargingStationStatisticsWeekList(jsonParam.getStr("orgId"));
            Integer allCount = 0;//总数目
            Integer weekVoltageCount = 0;//电压报警数目
            Integer weekCurrentCount = 0;//电流报警数目
            Integer weekTemperatureCount = 0;//温度报警数目
            Integer weekLeakageCurrentCount = 0;//漏电流报警数目
            for (DeviceAlarmLogChargingStationStatisticsWeek dw : deviceAlarmLogElectricFireStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekVoltageCount = weekVoltageCount + Integer.parseInt(dw.getWeekVoltageCount());
                    weekCurrentCount = weekCurrentCount + Integer.parseInt(dw.getWeekCurrentCount());
                    weekTemperatureCount = weekTemperatureCount + Integer.parseInt(dw.getWeekTemperatureCount());
                    weekLeakageCurrentCount = weekLeakageCurrentCount + Integer.parseInt(dw.getWeekLeakageCurrentCount());
                }
            }
            allCount = weekVoltageCount + weekCurrentCount + weekTemperatureCount + weekLeakageCurrentCount;
            map.put("weekVoltageCount",weekVoltageCount);
            map.put("weekCurrentCount",weekCurrentCount);
            map.put("weekTemperatureCount",weekTemperatureCount);
            map.put("weekLeakageCurrentCount",weekLeakageCurrentCount);
            map.put("allCount",allCount);
        }
        return map;
    }
    /**
     * @Author YangYu
     * @Description 本月报警数据报警数据
     * @Date Created in 14:59 2022/6/2
     * @Param [jsonParam]
     */

    public RespEntity monthAlarmLog(JSONObject jsonParam) {
        //处理支持form-data和json两种方式
        jsonParam = HttpRequestUtil.commonHttpRequestParamConvert(getRequest());
        //调用token验证接口
        com.alibaba.fastjson.JSONObject token = makeDataForToken(jsonParam,"systemsetup","config","getDecodeToken","systemsetup");
        if(StrUtil.isNotBlank(token.getString("methodCodeFlag"))) return RespEntity.expire();
        if(StrUtil.isNotBlank(token.getString("methodErrorFlag"))) return RespEntity.fail(token.getString("msg"));
        String homeId = token.getString("home_id");
        String userType = token.getString("user_type");
        if(userType.equals("1")){//为机构用户
            //rest请求系统设置模块的机构和子机构列表接口
            if(StrUtil.isNotBlank(jsonParam.getStr("businessId"))){//机构用户访问单位用户的数据
                jsonParam.put("businessId",jsonParam.getStr("businessId"));
            }else{
                jsonParam.put("orgId",homeId);
            }
        }else if(userType.equals("2")){//为单位用户
            jsonParam.put("businessId",homeId);
        }
        //系统类型
        String deviceClassify = jsonParam.getStr("deviceClassify");
        List<Map<String, Object>> insertList = new ArrayList<>();
        if (userType.equals("1")){
            if (StrUtil.isBlank(deviceClassify)){
                List<DeviceAlarmLogAllStatisticsWeek> deviceAlarmLogAllStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogAllStatisticsDateWeekList();
                for (DeviceAlarmLogAllStatisticsWeek dl : deviceAlarmLogAllStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapWeekList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("1")){
                List<DeviceAlarmLogElectricFireStatisticsWeek> deviceAlarmLogElectricFireStatisticsWeekDateList = deviceAlarmLogElectricFireStatisticsWeekMapper.deviceAlarmLogElectricFireStatisticsMonthDateList();
                for (DeviceAlarmLogElectricFireStatisticsWeek dl : deviceAlarmLogElectricFireStatisticsWeekDateList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapMonthList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("2")){
                List<DeviceAlarmLogFireWaterStatisticsWeek> deviceAlarmLogWaterStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogWaterStatisticsDateMonthList();
                for (DeviceAlarmLogFireWaterStatisticsWeek dl : deviceAlarmLogWaterStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapMonthList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("3")){
                List<DeviceAlarmLogSmokeStatisticsWeek> deviceAlarmLogSmokeStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogSmokeStatisticsDateMonthList();
                for (DeviceAlarmLogSmokeStatisticsWeek dl : deviceAlarmLogSmokeStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapMonthList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("4")){
                List<DeviceAlarmLogGasStatisticsWeek> deviceAlarmLogGasStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogGasStatisticsDateMonthList();
                for (DeviceAlarmLogGasStatisticsWeek dl : deviceAlarmLogGasStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapMonthList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("5")){
                List<DeviceAlarmLogAutoNetworkStatisticsWeek> deviceAlarmLogAutoNetStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogAutoNetStatisticsDateMonthList();
                for (DeviceAlarmLogAutoNetworkStatisticsWeek dl : deviceAlarmLogAutoNetStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapMonthList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("6") || deviceClassify.equals("11") || deviceClassify.equals("12") || deviceClassify.equals("13")){
                List<DeviceAlarmLogVisualizationStatisticsWeek> deviceAlarmLogVisualizationStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogVisualizationStatisticsDateMonthList();
                for (DeviceAlarmLogVisualizationStatisticsWeek dl : deviceAlarmLogVisualizationStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapMonthList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("7")){
                List<DeviceAlarmLogFireExtinguisherStatisticsWeek> deviceAlarmLogFireExtinguisherStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogFireExtinguisherStatisticsDateMonthList();
                for (DeviceAlarmLogFireExtinguisherStatisticsWeek dl : deviceAlarmLogFireExtinguisherStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapMonthList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("10")){
                List<DeviceAlarmLogWaterPumpStatisticsWeek> deviceAlarmLogWaterPumpStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogWaterPumpStatisticsDateMonthList();
                for (DeviceAlarmLogWaterPumpStatisticsWeek dl : deviceAlarmLogWaterPumpStatisticsDateWeekList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapMonthList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }else if (deviceClassify.equals("22")){
                List<DeviceAlarmLogChargingStationStatisticsWeek> deviceAlarmLogChargingStationStatisticsMonthDateList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogChargingStationStatisticsMonthDateList();
                for (DeviceAlarmLogChargingStationStatisticsWeek dl : deviceAlarmLogChargingStationStatisticsMonthDateList){
                    Map<String, Object> map = new HashMap<>();
                    map.put("date",dl.getDate());
                    map.put("alldate",dl.getAlldate());
                    map = getMapMonthList(map,dl.getDate(),deviceClassify,jsonParam);
                    insertList.add(map);
                }
            }

        }else if (userType.equals("2")){
            if (StrUtil.isBlank(deviceClassify)){
                List<DeviceAlarmLogAllStatisticsWeek> deviceAlarmLogAllStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogAllStatisticsBusinessWeekList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogAllStatisticsDateWeekList);
            }else if (deviceClassify.equals("1")){
                List<DeviceAlarmLogElectricFireStatisticsWeek> deviceAlarmLogElectricFireStatisticsWeekDateList = deviceAlarmLogElectricFireStatisticsWeekMapper.deviceAlarmLogElectricFireStatisticsBusinessMonthList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogElectricFireStatisticsWeekDateList);
            }else if (deviceClassify.equals("2")){
                List<DeviceAlarmLogFireWaterStatisticsWeek> deviceAlarmLogWaterStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogWaterStatisticsBusinessMonthList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogWaterStatisticsDateWeekList);
            }else if (deviceClassify.equals("3")){
                List<DeviceAlarmLogSmokeStatisticsWeek> deviceAlarmLogSmokeStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogSmokeStatisticsBusinessMonthList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogSmokeStatisticsDateWeekList);
            }else if (deviceClassify.equals("4")){
                List<DeviceAlarmLogGasStatisticsWeek> deviceAlarmLogGasStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogGasStatisticsBusinessMonthList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogGasStatisticsDateWeekList);
            }else if (deviceClassify.equals("5")){
                List<DeviceAlarmLogAutoNetworkStatisticsWeek> deviceAlarmLogAutoNetStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogAutoNetStatisticsBusinessMonthList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogAutoNetStatisticsDateWeekList);
            }else if (deviceClassify.equals("6") || deviceClassify.equals("11") || deviceClassify.equals("12") || deviceClassify.equals("13")){
                List<DeviceAlarmLogVisualizationStatisticsWeek> deviceAlarmLogVisualizationStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogVisualizationStatisticsBusinessMonthList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogVisualizationStatisticsDateWeekList);
            }else if (deviceClassify.equals("7")){
                List<DeviceAlarmLogFireExtinguisherStatisticsWeek> deviceAlarmLogFireExtinguisherStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogFireExtinguisherStatisticsBusinessMonthList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogFireExtinguisherStatisticsDateWeekList);
            }else if (deviceClassify.equals("10")){
                List<DeviceAlarmLogWaterPumpStatisticsWeek> deviceAlarmLogWaterPumpStatisticsDateWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogWaterPumpStatisticsBusinessMonthList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogWaterPumpStatisticsDateWeekList);
            }else if (deviceClassify.equals("10")){
                List<DeviceAlarmLogChargingStationStatisticsWeek> deviceAlarmLogChargingStationStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogChargingStationStatisticsBusinessMonthList(jsonParam.getStr("businessId"));
                return RespEntity.success(deviceAlarmLogChargingStationStatisticsWeekList);
            }
        }
        return RespEntity.success(insertList);
    }
    public Map<String, Object> getMapMonthList(Map<String, Object> map,String date,String deviceClassify,JSONObject jsonParam) {
        if (StrUtil.isBlank(deviceClassify)){
            List<DeviceAlarmLogAllStatisticsWeek> deviceAlarmLogAllStatisticsWeeks = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogAllStatisticsWeekList(jsonParam.getStr("orgId"));
            Integer allCount = 0;//总数目
            Integer weeOtherCount = 0;//其他数目
            Integer weeFileCount = 0;//电气火灾报警数目
            Integer weeWaterCount = 0;//消防用水报警数目
            Integer weeSmokeCount = 0;//烟感报警数目
            Integer weeGasCount = 0;//气体报警数目
            Integer weeSmartEyeCount = 0;//慧眼识别报警数目
            Integer weeFireExtinguisherCount = 0;//灭火器报警数目
            Integer weeWaterImmersionCount = 0;//水浸报警数目
            for (DeviceAlarmLogAllStatisticsWeek dw : deviceAlarmLogAllStatisticsWeeks){
                if (dw.getDate().equals(date)){
                    weeOtherCount = weeOtherCount + Integer.parseInt(dw.getWeeOtherCount());
                    weeFileCount = weeFileCount + Integer.parseInt(dw.getWeeFileCount());
                    weeWaterCount = weeWaterCount + Integer.parseInt(dw.getWeeWaterCount());
                    weeSmokeCount = weeSmokeCount + Integer.parseInt(dw.getWeeSmokeCount());
                    weeGasCount = weeGasCount + Integer.parseInt(dw.getWeeGasCount());
                    weeSmartEyeCount = weeSmartEyeCount + Integer.parseInt(dw.getWeeSmartEyeCount());
                    weeFireExtinguisherCount = weeFireExtinguisherCount + Integer.parseInt(dw.getWeeFireExtinguisherCount());
                    weeWaterImmersionCount = weeWaterImmersionCount + Integer.parseInt(dw.getWeeWaterImmersionCount());
                }
            }
            allCount = weeOtherCount + weeFileCount + weeWaterCount + weeSmokeCount + weeGasCount + weeSmartEyeCount + weeFireExtinguisherCount + weeWaterImmersionCount;
            map.put("weeFileCount", weeFileCount);
            map.put("weeWaterCount", weeWaterCount);
            map.put("weeSmokeCount", weeSmokeCount);
            map.put("weeOtherCount", weeOtherCount);
            map.put("weeGasCount", weeGasCount);
            map.put("weeSmartEyeCount", weeSmartEyeCount);
            map.put("weeFireExtinguisherEyeCount", weeFireExtinguisherCount);
            map.put("weeWaterImmersionCount", weeWaterImmersionCount);
            map.put("allCount", allCount);
        }else if (deviceClassify.equals("1")){
            List<DeviceAlarmLogElectricFireStatisticsWeek> deviceAlarmLogElectricFireStatisticsWeekList = deviceAlarmLogElectricFireStatisticsWeekMapper.deviceAlarmLogElectricFireStatisticsMonthList(jsonParam.getStr("orgId"));
            Integer allCount = 0;//总数目
            Integer weekVoltageCount = 0;//电压报警数目
            Integer weekCurrentCount = 0;//电流报警数目
            Integer weekTemperatureCount = 0;//温度报警数目
            Integer weekLeakageCurrentCount = 0;//漏电流报警数目
            for (DeviceAlarmLogElectricFireStatisticsWeek dw : deviceAlarmLogElectricFireStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekVoltageCount = weekVoltageCount + Integer.parseInt(dw.getWeekVoltageCount());
                    weekCurrentCount = weekCurrentCount + Integer.parseInt(dw.getWeekCurrentCount());
                    weekTemperatureCount = weekTemperatureCount + Integer.parseInt(dw.getWeekTemperatureCount());
                    weekLeakageCurrentCount = weekLeakageCurrentCount + Integer.parseInt(dw.getWeekLeakageCurrentCount());
                }
            }
            allCount = weekVoltageCount + weekCurrentCount + weekTemperatureCount + weekLeakageCurrentCount;
            map.put("weekVoltageCount",weekVoltageCount);
            map.put("weekCurrentCount",weekCurrentCount);
            map.put("weekTemperatureCount",weekTemperatureCount);
            map.put("weekLeakageCurrentCount",weekLeakageCurrentCount);
            map.put("allCount",allCount);
        }else if (deviceClassify.equals("2")){
            Integer allCount = 0;//总数目
            Integer weekHydraulicPressureCount = 0;//液压报警数目
            Integer weekLevelCount = 0;//液位报警数目
            List<DeviceAlarmLogFireWaterStatisticsWeek> deviceAlarmLogWaterStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogWaterStatisticsMonthList(jsonParam.getStr("orgId"));
            for (DeviceAlarmLogFireWaterStatisticsWeek dw : deviceAlarmLogWaterStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekHydraulicPressureCount = weekHydraulicPressureCount + Integer.parseInt(dw.getWeekHydraulicPressureCount());
                    weekLevelCount = weekLevelCount + Integer.parseInt(dw.getWeekLevelCount());
                }
            }
            allCount = weekHydraulicPressureCount + weekLevelCount;
            map.put("weekHydraulicPressureCount", weekHydraulicPressureCount);
            map.put("weekLevelCount", weekLevelCount);
            map.put("allCount", allCount);
        }else if (deviceClassify.equals("3")){
            Integer allCount = 0;//总数目
            Integer weekSmokeCount = 0;//独立烟感报警
            Integer weekSignalCount = 0;//信号异常报警
            List<DeviceAlarmLogSmokeStatisticsWeek> deviceAlarmLogSmokeStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogSmokeStatisticsMonthList(jsonParam.getStr("orgId"));
            for (DeviceAlarmLogSmokeStatisticsWeek dw : deviceAlarmLogSmokeStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekSmokeCount = weekSmokeCount + Integer.parseInt(dw.getWeekSmokeCount());
                    weekSignalCount = weekSignalCount + Integer.parseInt(dw.getWeekSignalCount());
                }
            }
            allCount = weekSmokeCount + weekSignalCount;
            map.put("weekSmokeCount", weekSmokeCount);
            map.put("weekSignalCount", weekSignalCount);
            map.put("allCount", allCount);
        }else if (deviceClassify.equals("4")){
            Integer allCount = 0;//总数目
            Integer weekGasCount = 0;//可燃气报警
            List<DeviceAlarmLogGasStatisticsWeek> deviceAlarmLogGasStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogGasStatisticsMonthList(jsonParam.getStr("orgId"));
            for (DeviceAlarmLogGasStatisticsWeek dw : deviceAlarmLogGasStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekGasCount = weekGasCount + Integer.parseInt(dw.getWeekGasCount());
                }
            }
            map.put("weekGasCount", weekGasCount);
            map.put("allCount", weekGasCount);
        }else if (deviceClassify.equals("5")){
            Integer allCount = 0;//总数目
            Integer weekSystemEventCount = 0;//系统事件
            Integer weekFaultCount = 0;//故障
            Integer weekFireAlarmCount = 0;//火警
            List<DeviceAlarmLogAutoNetworkStatisticsWeek> deviceAlarmLogAutoNetStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogAutoNetStatisticsMonthList(jsonParam.getStr("orgId"));
            for (DeviceAlarmLogAutoNetworkStatisticsWeek dw : deviceAlarmLogAutoNetStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekSystemEventCount = weekSystemEventCount + Integer.parseInt(dw.getWeekSystemEventCount());
                    weekFaultCount = weekFaultCount + Integer.parseInt(dw.getWeekFaultCount());
                    weekFireAlarmCount = weekSystemEventCount + Integer.parseInt(dw.getWeekFireAlarmCount());
                }
            }
            allCount = weekSystemEventCount + weekFaultCount + weekFireAlarmCount;
            map.put("weekSystemEventCount", weekSystemEventCount);
            map.put("weekFaultCount", weekFaultCount);
            map.put("weekFireAlarmCount", weekFireAlarmCount);
            map.put("allCount", allCount);
        }else if (deviceClassify.equals("6") || deviceClassify.equals("11") || deviceClassify.equals("12") || deviceClassify.equals("13")){
            Integer allCount = 0;//总数目
            Integer weekFireCount = 0;//火焰报警
            Integer weekLeaveCount = 0;//脱岗离岗报警
            Integer weekPassWayCount = 0;//消防通道报警
            Integer weekElectricVehicleCount = 0;//电动车报警
            Integer weekPersonnelDetectionCount = 0;//人员检测
            Integer weekUnloadingAnalysisCount = 0;//卸油分析
            Integer weekAlertIdentificationCount = 0;//警戒识别
            Integer weekVideoOcclusionCount = 0;//视频遮挡
            List<DeviceAlarmLogVisualizationStatisticsWeek> deviceAlarmLogVisualizationStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogVisualizationStatisticsMonthList(jsonParam.getStr("orgId"));
            for (DeviceAlarmLogVisualizationStatisticsWeek dw : deviceAlarmLogVisualizationStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekFireCount = weekFireCount + Integer.parseInt(dw.getWeekFireCount());
                    weekLeaveCount = weekLeaveCount + Integer.parseInt(dw.getWeekLeaveCount());
                    weekPassWayCount = weekPassWayCount + Integer.parseInt(dw.getWeekPassWayCount());
                    weekElectricVehicleCount = weekElectricVehicleCount + Integer.parseInt(dw.getWeekElectricVehicleCount());
                    weekPersonnelDetectionCount = weekPersonnelDetectionCount + Integer.parseInt(dw.getWeekPersonnelDetectionCount());
                    weekUnloadingAnalysisCount = weekUnloadingAnalysisCount + Integer.parseInt(dw.getWeekUnloadingAnalysisCount());
                    weekAlertIdentificationCount = weekAlertIdentificationCount + Integer.parseInt(dw.getWeekAlertIdentificationCount());
                    weekVideoOcclusionCount = weekVideoOcclusionCount + Integer.parseInt(dw.getWeekVideoOcclusionCount());
                }
            }
            map.put("weekFireCount", weekFireCount);
            map.put("weekLeaveCount", weekLeaveCount);
            map.put("weekPassWayCount", weekPassWayCount);
            map.put("weekElectricVehicleCount", weekElectricVehicleCount);
            map.put("weekPersonnelDetectionCount", weekPersonnelDetectionCount);
            map.put("weekUnloadingAnalysisCount", weekUnloadingAnalysisCount);
            map.put("weekAlertIdentificationCount", weekAlertIdentificationCount);
            map.put("weekVideoOcclusionCount", weekVideoOcclusionCount);
            map.put("allCount", allCount);
        }else if (deviceClassify.equals("7")){
            Integer allCount = 0;//总数目
            Integer weekPressureCount = 0;//压力报警
            Integer weekEmbezzlementCount = 0;//挪用报警
            List<DeviceAlarmLogFireExtinguisherStatisticsWeek> deviceAlarmLogFireExtinguisherStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogFireExtinguisherStatisticsMonthList(jsonParam.getStr("orgId"));
            for (DeviceAlarmLogFireExtinguisherStatisticsWeek dw : deviceAlarmLogFireExtinguisherStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekPressureCount = weekPressureCount + Integer.parseInt(dw.getWeekPressureCount());
                    weekEmbezzlementCount = weekEmbezzlementCount + Integer.parseInt(dw.getWeekEmbezzlementCount());
                }
            }
            allCount = weekPressureCount + weekEmbezzlementCount;
            map.put("weekPressureCount", weekPressureCount);
            map.put("weekEmbezzlementCount", weekEmbezzlementCount);
            map.put("allCount", allCount);
        }else if (deviceClassify.equals("10")){
            Integer allCount = 0;//总数目
            Integer weekVoltageCount = 0;//电压故障报警数目
            List<DeviceAlarmLogWaterPumpStatisticsWeek> deviceAlarmLogWaterPumpStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogWaterPumpStatisticsMonthList(jsonParam.getStr("orgId"));
            for (DeviceAlarmLogWaterPumpStatisticsWeek dw : deviceAlarmLogWaterPumpStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekVoltageCount = weekVoltageCount + Integer.parseInt(dw.getWeekVoltageCount());
                }
            }
            map.put("weekVoltageCount", weekVoltageCount);
            map.put("allCount", weekVoltageCount);
        }else if (deviceClassify.equals("22")){
            List<DeviceAlarmLogChargingStationStatisticsWeek> deviceAlarmLogChargingStationStatisticsWeekList = deviceAlarmLogAllStatisticsWeekMapper.deviceAlarmLogChargingStationStatisticsMonthList(jsonParam.getStr("orgId"));
            Integer allCount = 0;//总数目
            Integer weekVoltageCount = 0;//电压报警数目
            Integer weekCurrentCount = 0;//电流报警数目
            Integer weekTemperatureCount = 0;//温度报警数目
            Integer weekLeakageCurrentCount = 0;//漏电流报警数目
            for (DeviceAlarmLogChargingStationStatisticsWeek dw : deviceAlarmLogChargingStationStatisticsWeekList){
                if (dw.getDate().equals(date)){
                    weekVoltageCount = weekVoltageCount + Integer.parseInt(dw.getWeekVoltageCount());
                    weekCurrentCount = weekCurrentCount + Integer.parseInt(dw.getWeekCurrentCount());
                    weekTemperatureCount = weekTemperatureCount + Integer.parseInt(dw.getWeekTemperatureCount());
                    weekLeakageCurrentCount = weekLeakageCurrentCount + Integer.parseInt(dw.getWeekLeakageCurrentCount());
                }
            }
            allCount = weekVoltageCount + weekCurrentCount + weekTemperatureCount + weekLeakageCurrentCount;
            map.put("weekVoltageCount",weekVoltageCount);
            map.put("weekCurrentCount",weekCurrentCount);
            map.put("weekTemperatureCount",weekTemperatureCount);
            map.put("weekLeakageCurrentCount",weekLeakageCurrentCount);
            map.put("allCount",allCount);
        }
        return map;
    }
    public Map<String, Object>  getTodayWeek(String table, String deviceClassify) {
        JSONObject jsonParam = new JSONObject();
        jsonParam.put("table", table);
        jsonParam.put("deviceClassify", deviceClassify);
        List<Map<String, Object>> insertList = getInsertList(jsonParam);
        Map<String, Object> map = new HashMap<>();

        return map;
    }
}
